package com.itheima.web.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.Movies;
import com.itheima.service.MoviesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/movies")
public class MoviesController {
        @Autowired
        private MoviesService moviesService;

        @GetMapping("/findByPage")
        public PageInfo<Movies> findByPage(@RequestParam(value = "pageNum",defaultValue ="1") Integer pageNum,
                                            @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
                                            Integer cid,String keyword){

            PageInfo<Movies> pageInfo = moviesService.findByPage(pageNum, pageSize,cid,keyword);
            return pageInfo;
        }

        @PostMapping("/save")
         public String save(@RequestBody Movies movies){
            moviesService.save(movies);
            return "ok";
        }

        @GetMapping("findById")
        public Movies findById(Integer id){

            return moviesService.findById(id);
        }

        @DeleteMapping("deleteById")
        public String deleteById(Integer id){
            moviesService.deleteById(id);
            return "ok";
        }

    @DeleteMapping("deleteBatch")
    public String deleteBatch(Integer[] ids){
        moviesService.deleteBatch(ids);
        return "ok";
    }

}
